package cd.tools_test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

import cd.serialport.Serialport;
import cd.tools.Tools;

public class ToolTestActivity extends AppCompatActivity {

    private Serialport mSerialport;
    private int fd;
    private TextView tvOutput;
    private EditText etInput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_serialport);

        tvOutput = (TextView) findViewById(R.id.tvOutput);
        tvOutput.setMovementMethod(ScrollingMovementMethod.getInstance());
        etInput = (EditText) findViewById(R.id.etInput);

        Log.d("chenda","Tools.getVersion() :  " + Tools.getVersion());

        Tools.test();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    public void tvAppend(String data) {
        tvOutput.append(data);
        int offset = tvOutput.getLineCount() * tvOutput.getLineHeight();
        if (offset > tvOutput.getHeight()) {
            tvOutput.scrollTo(0, offset - tvOutput.getHeight());
        }
    }
}
